      SUBROUTINE  TABLE(LAY,DEPTH,ISTEP)
      REAL*8  RAD,TMASS,GS,RHO0,GA
      REAL*8  D,H,RHO,ELAMB,EMU,GR,XI,PHI,ETA
      COMMON/MODEL /NLAY,ISO,LAME,NDIV,DMAX,ILAY,
     1              RAD,TMASS,GS,RHO0,GA,
     2              HI(500),RHOI(500),VPI(500),VSI(500),NAME(20),
     3              XII(500),PHII(500),ETAI(500),
     4              D(1000),H(1000),RHO(1000),ELAMB(1000),EMU(1000),
     5              GR(1000),XI(1000),PHI(1000),ETA(1000)
C
C PURPOSE -   TO FIND  LAY  SUCH THAT  ABS(DEPTH-D(LAY))=MIN.
C     IF THERE ARE TWO SOLUTIONS, LAY TAKES THE LARGER ONE.
C
      DIF=1.0E+20
      I=1
      J=0
  100 CONTINUE
      IF(H(I+1))  200,110,200
  110 CONTINUE
      I=I+1
  200 CONTINUE
      DIFF=D(I)-DEPTH
      IF(DIFF)  250,250,300
  250 CONTINUE
      DIF=DIFF
      J=I
      I=I+ISTEP
      IF(I-NLAY)  100,200,1000
  300 CONTINUE
      IF(ABS(DIFF)-ABS(DIF))  310,310,1000
  310 CONTINUE
      J=I
C
C EXIT
C
 1000 CONTINUE
      LAY=J
      RETURN
      END
